home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / GLUT-3.7 / LIB / FGLUT / FGLUT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-12  |  6.5 KB  |  288 lines

  1.  
  2. /* Copyright (c) Mark J. Kilgard, 1994. */
  3.  
  4. /* This program is freely distributable without licensing fees
  5.    and is provided without guarantee or warrantee expressed or
  6.    implied. This program is -not- in the public domain. */
  7.  
  8. #ifndef WRAPPERS_ONLY
  9.  
  10. #include <glutint.h>
  11.  
  12. extern int __Argc;
  13. extern char **__Argv;
  14.  
  15. static GLUTmenuStateFCB fortranMenuStateFunc;
  16.  
  17. void
  18. glutnull_(void)
  19. {
  20. }
  21.  
  22. void
  23. glutinit_(void)
  24. {
  25.   glutInit(&__Argc, __Argv);
  26. }
  27.  
  28. static void
  29. fortranMenuStateWrapper(int value)
  30. {
  31.   fortranMenuStateFunc(&value);
  32. }
  33.  
  34. static void
  35. fortranReshapeWrapper(int w, int h)
  36. {
  37.   (*__glutCurrentWindow->freshape) (&w, &h);
  38. }
  39.  
  40. #if 0  /* XXX No IRIX joystick support for now. */
  41. static void
  42. fortranJoystickWrapper(unsigned int button, int x, int y, int z)
  43. {
  44.   (*__glutCurrentWindow->fjoystick) (&button, &x, &y, &z);
  45. }
  46. #endif
  47.  
  48. static void
  49. fortranKeyboardWrapper(unsigned char ch, int x, int y)
  50. {
  51.   int chi = ch;
  52.  
  53.   (*__glutCurrentWindow->fkeyboard) (&chi, &x, &y);
  54. }
  55.  
  56. static void
  57. fortranKeyboardUpWrapper(unsigned char ch, int x, int y)
  58. {
  59.   int chi = ch;
  60.  
  61.   (*__glutCurrentWindow->fkeyboardUp) (&chi, &x, &y);
  62. }
  63.  
  64. static void
  65. fortranMouseWrapper(int btn, int state, int x, int y)
  66. {
  67.   (*__glutCurrentWindow->fmouse) (&btn, &state, &x, &y);
  68. }
  69.  
  70. static void
  71. fortranMotionWrapper(int x, int y)
  72. {
  73.   (*__glutCurrentWindow->fmotion) (&x, &y);
  74. }
  75.  
  76. static void
  77. fortranPassiveMotionWrapper(int x, int y)
  78. {
  79.   (*__glutCurrentWindow->fpassive) (&x, &y);
  80. }
  81.  
  82. static void
  83. fortranEntryWrapper(int state)
  84. {
  85.   (*__glutCurrentWindow->fentry) (&state);
  86. }
  87.  
  88. static void
  89. fortranVisibilityWrapper(int state)
  90. {
  91.   (*__glutCurrentWindow->fvisibility) (&state);
  92. }
  93.  
  94. static void
  95. fortranTimerWrapper(int value)
  96. {
  97.   /* Relies on special knowledge that __glutTimerList points to 
  98.      the GLUTtimer* currently being processed! */
  99.   (*__glutTimerList->ffunc) (&value);
  100. }
  101.  
  102. static void
  103. fortranSelectWrapper(int value)
  104. {
  105.   (*__glutItemSelected->menu->fselect) (&value);
  106. }
  107.  
  108. static void
  109. fortranSpecialWrapper(int key, int x, int y)
  110. {
  111.   (*__glutCurrentWindow->fspecial) (&key, &x, &y);
  112. }
  113.  
  114. static void
  115. fortranSpecialUpWrapper(int key, int x, int y)
  116. {
  117.   (*__glutCurrentWindow->fspecialUp) (&key, &x, &y);
  118. }
  119.  
  120. static void
  121. fortranSpaceballMotionWrapper(int x, int y, int z)
  122. {
  123.   (*__glutCurrentWindow->fspaceMotion) (&x, &y, &z);
  124. }
  125.  
  126. static void
  127. fortranSpaceballRotateWrapper(int x, int y, int z)
  128. {
  129.   (*__glutCurrentWindow->fspaceRotate) (&x, &y, &z);
  130. }
  131.  
  132. static void
  133. fortranSpaceballButtonWrapper(int button, int state)
  134. {
  135.   (*__glutCurrentWindow->fspaceButton) (&button, &state);
  136. }
  137.  
  138. static void
  139. fortranTabletMotionWrapper(int x, int y)
  140. {
  141.   (*__glutCurrentWindow->ftabletMotion) (&x, &y);
  142. }
  143.  
  144. static void
  145. fortranTabletButtonWrapper(int button, int state, int x, int y)
  146. {
  147.   (*__glutCurrentWindow->ftabletButton) (&button, &state, &x, &y);
  148. }
  149.  
  150. static void
  151. fortranDialsWrapper(int dial, int value)
  152. {
  153.   (*__glutCurrentWindow->fdials) (&dial, &value);
  154. }
  155.  
  156. static void
  157. fortranButtonBoxWrapper(int button, int state)
  158. {
  159.   (*__glutCurrentWindow->fbuttonBox) (&button, &state);
  160. }
  161.  
  162. #endif /* WRAPPERS_ONLY */
  163.  
  164. #define glutfunc(Name,name,mixed,type) \
  165. void \
  166. glut##name##func(GLUT##type##FCB mixed) \
  167. { \
  168.     if(mixed == (GLUT##type## FCB) glutnull_) { \
  169.     glut##Name ## Func(NULL); \
  170.     } else { \
  171.     glut##Name##Func(fortran##Name##Wrapper); \
  172.     __glutCurrentWindow->f##mixed = mixed; \
  173.     } \
  174. }
  175.  
  176. glutfunc(Reshape, reshape, reshape, reshape)
  177. glutfunc(Keyboard, keyboard, keyboard, keyboard)
  178. glutfunc(KeyboardUp, keyboardup, keyboardUp, keyboard)
  179. glutfunc(Mouse, mouse, mouse, mouse)
  180. glutfunc(Motion, motion, motion, motion)
  181. glutfunc(Entry, entry, entry, entry)
  182. glutfunc(Visibility, visibility, visibility, visibility)
  183. glutfunc(Special, special, special, special)
  184. glutfunc(SpecialUp, specialup, specialUp, special)
  185. glutfunc(Dials, dials, dials, dials)
  186. glutfunc(SpaceballMotion, spaceballmotion, spaceMotion, spaceMotion)
  187. glutfunc(SpaceballRotate, spaceballrotate, spaceRotate, spaceRotate)
  188. glutfunc(SpaceballButton, spaceballbutton, spaceButton, spaceButton)
  189. glutfunc(PassiveMotion, passivemotion, passive, passive)
  190. glutfunc(ButtonBox, buttonbox, buttonBox, buttonBox)
  191. glutfunc(TabletMotion, tabletmotion, tabletMotion, tabletMotion)
  192. glutfunc(TabletButton, tabletbutton, tabletButton, tabletButton)
  193.  
  194. /* Special callback cases. */
  195.  
  196. /* The display has no parameters passed so no need for wrapper. */
  197. void
  198. glutdisplayfunc(GLUTdisplayFCB display)
  199. {
  200.   glutDisplayFunc((GLUTdisplayCB) display);
  201. }
  202.  
  203. int
  204. glutcreatemenu(GLUTselectFCB select)
  205. {
  206.   int menu;
  207.  
  208.   menu = glutCreateMenu(fortranSelectWrapper);
  209.   __glutCurrentMenu->fselect = select;
  210.   return menu;
  211. }
  212.  
  213. void
  214. gluttimerfunc(unsigned long interval, GLUTtimerFCB timer, int value)
  215. {
  216.   glutTimerFunc((unsigned int) interval, fortranTimerWrapper, value);
  217.   /* Relies on special __glutNewTimer variable side effect to
  218.      establish Fortran timer func! */
  219.   __glutNewTimer->ffunc = timer;
  220. }
  221.  
  222. /* ARGSUSED */
  223. void
  224. glutjoystickfunc(GLUTjoystickFCB joystick, int pollInterval)
  225. {
  226. #if 0  /* XXX No IRIX joystick support for now. */
  227.   if(joystick == (GLUTjoystickFCB) glutnull_) {
  228.     glutJoystickFunc(NULL, pollInterval);
  229.   } else {
  230.     glutJoystickFunc(fortranJoystickWrapper, pollInterval);
  231.     __glutCurrentWindow->fjoystick = joystick;
  232.   }
  233. #endif
  234. }
  235.  
  236. void
  237. glutidlefunc(GLUTidleFCB idleFunc)
  238. {
  239.   if (idleFunc == (GLUTidleFCB) glutnull_) {
  240.     glutIdleFunc(NULL);
  241.   } else {
  242.     glutIdleFunc(idleFunc);
  243.   }
  244. }
  245.  
  246. void
  247. glutmenustatefunc(GLUTmenuStateFCB menuStateFunc)
  248. {
  249.   if (menuStateFunc == (GLUTmenuStateFCB) glutnull_) {
  250.     glutMenuStateFunc(NULL);
  251.   } else {
  252.     glutMenuStateFunc(fortranMenuStateWrapper);
  253.     fortranMenuStateFunc = menuStateFunc;
  254.   }
  255. }
  256.  
  257. void
  258. glutbitmapcharacter(int *font, int ch)
  259. {
  260.   /* 
  261.    * mkf2c gets confused by double pointers and void* pointers.
  262.    * So mkf2c does not complain, we consider the font handle to
  263.    * be an int*.  But we really get an int** since Fortran
  264.    * passes by reference.  So to "pedantically decode" the 
  265.    * pointer, cast it first to int**, then dereference it,
  266.    * then cast the result to a void*.
  267.    */
  268.   void *trueFont = (void *) *((int **) font);
  269.  
  270.   glutBitmapCharacter(trueFont, ch);
  271. }
  272.  
  273. void
  274. glutstrokecharacter(int *font, int ch)
  275. {
  276.   /* 
  277.    * mkf2c gets confused by double pointers and void* pointers.
  278.    * So mkf2c does not complain, we consider the font handle to
  279.    * be an int*.  But we really get an int** since Fortran
  280.    * passes by reference.  So to "pedantically decode" the 
  281.    * pointer, cast it first to int**, then dereference it,
  282.    * then cast the result to a void*.
  283.    */
  284.   void *trueFont = (void *) *((int **) font);
  285.  
  286.   glutStrokeCharacter(trueFont, ch);
  287. }
  288.